<?php

namespace App\Services\MiniprogramToGame\HotSearch;

use App\Services\ServiceBase;
use App\Structs\HotSearchStruct;
use Illuminate\Support\Facades\Http;

class Qq extends ServiceBase
{
    public function reptile()
    {
        $url = 'https://r.inews.qq.com/gw/event/pc_hot_ranking_list';
        $response = Http::get($url);
        if (!$response->ok()) {
            return false;
        }

        $data = json_decode($response->body(), true);

        $list = [];
        foreach ($data['idlist'][0]['newslist'] as $item) {
            if (!isset($item['hotEvent']['hotScore'])) {
                continue;
            }
            $class           = new HotSearchStruct;
            $class->title    = $item['hotEvent']['title'];
            $class->desc     = $item['title'];
            $class->hotIndex = $item['ranking'];
            $class->hotValue = $item['hotEvent']['hotScore'];
            if ($item['hotEvent']['is_top']??0 == 1) {
                $class->isTop = 1;
            }
            $class->url = $item['url'];
            $class->img = $item['miniProShareImage'] ?? '';
            $list[] = $class;
        }

        return $list;
    }
}
